package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Mobile     string `gorm:"type:char(11);unique;comment:手机号"`
	Avatar     string `gorm:"type:varchar(200);not null;comment:头像"`
	UserStatus int64  `gorm:"type:tinyint(1);default:1;comment:用户状态:1:待审核,2:通过,3:不通过"`
}
type RealName struct {
	gorm.Model
	UserId   int64  `gorm:"type:int(11);comment:用户id"`
	RealName string `gorm:"type:char(3);comment:姓名"`
	IdCord   string `gorm:"type:char(18);unique;comment:身份证"`
}

func (u *User) Create() error {
	return Db.Create(&u).Error
}
func (u *User) UserMobile(mobile string) error {
	return Db.Where("mobile = ?", mobile).Limit(1).Find(&u).Error
}

func (u *User) UserUpdateStatus(userId, userStatus int64) error {
	return Db.Model(&User{}).Where("id = ?", userId).Update("user_status", userStatus).Error
}
func (u *User) UserUpdateAvatar(userId int64, avatar string) error {
	return Db.Model(&User{}).Where("id = ?", userId).Update("avatar", avatar).Error
}
func (u *User) UserList() (UserList []User, err error) {
	err = Db.Order("user_status").Limit(1).Find(&UserList).Error
	return
}
func (r *RealName) Create() error {
	return Db.Create(&r).Error
}
func (r *RealName) RealNameInfo(userId int64, realName string) error {
	return Db.Where("user_id = ? or real_name = ?", userId, realName).Limit(1).Find(&r).Error
}
